<?php

namespace app\controller;

use app\BaseController;
use think\exception\ValidateException;
use think\facade\Filesystem;
use think\facade\Request;
use tool\Zip;

class Index extends BaseController
{
    public function index()
    {
        $item = Request::param('item');
        $copy = Request::param('copy');
        switch ($item) {
            case '80f1c0a0695111ec9a7cb9e012460500':
                return $this->demo();
                break;
            case 2:
                return $this->demo2();
                break;
            case 'copy':
                return $this->copy($copy);
                break;
            case 'paste':
                return $this->paste();
                break;
            case 'upload':
                return $this->upload();
                break;
            case 'download':
                $this->download();
                break;
            case 'vncRestart':
                return $this->vncRestart();
                break;
            case '52d1c47e53baf3017a9efd949d3b64fc':
                return $this->online();
                break;
            case 'cd3fcc1a0aa949ed3e35793826fb5f0a':
                return $this->online1();
                break;
            case '45d9abc707a9a805764b98abd02ec97e':
                return $this->online2();
                break;
            case '6f4a9a7f4cdfb73af85cec6764c51acb':
                return $this->online3();
                break;
            case '52763b94c500ad10ae547b900d2712c6':
                return $this->online4();
                break;
            case 'e92dd59d1ad9e863585d9e208b92c91b':
                return $this->online5();
                break;
            case '277a03ad60a3e7d328b066a238946fae':
                return $this->online6();
                break;
            case '5accf08da4d553ddc1b51194f276dc8d':
                return $this->online7();
                break;
            case 'bca7024b7f29e209bf521cfea72242c9':
                return $this->online8();
                break;
            case 'b80a4f8660d87584f87f233dab8acfab':
                return $this->online9();
                break;
            case '2af082ebf12700db0305b5feedde0455':
                return $this->online10();
                break;
            case '494c3bb8c8d11b155aa778c891324698':
                return $this->online11();
                break;
            default:
                return json(['state' => 4000, 'msg' => '项目不存在']);
        }
    }

    private function upload()
    {
        $file = Request::file('file_upload');
        if (!$file) {
            return json(['state' => 4000, 'msg' => '文件不存在']);
        }
        try {
            validate(['file' => ['fileSize' => 10 * 1024 * 1024]],
                ['file.fileSize' => '文件大小超过10M'])->check(['file' => $file]);

            $path = Filesystem::disk('public')->putFile('upload', $file);
//            $picCover = Filesystem::getDiskConfig('public', 'url') . '/' . str_replace('\\', '/', $path);
//            $fileName = $file->getOriginalName();
            return json(['state' => 1, 'msg' => '上传成功']);
        } catch (ValidateException $e) {
            return json(['state' => 4000, 'msg' => $e->getMessage()]);
        }
    }

    private function download()
    {
        $dir = '/www/admin/localhost_80/wwwroot/yk/public/storage/upload';
        if (file_exists($dir)) {
            $sizeRes = getDirSize($dir);
            if ($sizeRes > 20 * 1024 * 1024) {
                return json(['state' => 500, 'data' => '', 'msg' => '下载的文件夹超过限制，请先清理']);
            }
            $zip = new Zip();
            $zip->zip_file($dir);
        } else {
            return json(['state' => 400, 'data' => '', 'msg' => '需要下载的文件夹不存在']);
        }
    }

    private function copy($copy)
    {
        $res = exec("python3.8 /www/admin/localhost_80/wwwroot/yk/app/controller/clipCopy.py $copy");
        if ($res) {
            return json(['state' => 1, 'data' => '', 'msg' => 'copy success']);
        }
        return json(['state' => 400, 'data' => '', 'msg' => 'copy error']);
    }

    private function paste()
    {
        $res = exec("python3.8 /www/admin/localhost_80/wwwroot/yk/app/controller/clipParse.py");
        return json(['state' => 1, 'data' => $res, 'msg' => 'paste success']);
    }

    private function demo()
    {
        $dir = '/root/桌面/img';
        $file = '/root/桌面/img/test.txt';
        if (file_exists($dir)) {
            if (file_exists($file)) {
                return json(['state' => 1, 'data' => [
                    [
                        'answer' => '[{"insert":"img文件夹存在\ntest文件存在\n"}]',
                        'res' => '[{"insert":"img文件夹存在\ntest文件存在\n"}]',
                    ]
                ], 'msg' => '']);
            }
            return json(['state' => 1, 'data' => [
                [
                    'answer' => '[{"insert":"img文件夹存在\ntest文件存在\n"}]',
                    'res' => '[{"insert":"img文件夹存在\ntest文件"},{"attributes":{"color":"#ff0000"},"insert":"不"},{"insert":"存在\n"}]',
                ]
            ], 'msg' => '']);
        } else {
            return json(['state' => 1, 'data' => [
                [
                    'answer' => '[{"insert":"img文件夹存在\ntest文件存在\n"}]',
                    'res' => '[{"insert":"img文件夹"},{"attributes":{"color":"#ff0000"},"insert":"不"},{"insert":"存在\ntest文件"},{"attributes":{"color":"#ff0000"},"insert":"不"},{"insert":"存在\n"}]',
                ]
            ], 'msg' => '']);
        }
    }

    private function demo2()
    {
        $dir = '/root/桌面/img';
        $file = '/root/桌面/img/test.txt';
        if (file_exists($dir)) {
            if (file_exists($file)) {
                return json(['state' => 1, 'data' => [
                    [
                        'answer' => '[{"insert":"img文件夹存在\n"}]',
                        'res' => '[{"insert":"img文件夹存在\n"}]',
                    ],
                    [
                        'answer' => '[{"insert":"test文件存在\n"}]',
                        'res' => '[{"insert":"test文件存在\n"}]',
                    ]
                ], 'msg' => '']);
            }
            return json(['state' => 1, 'data' => [
                [
                    'answer' => '[{"insert":"img文件夹存在\n"}]',
                    'res' => '[{"insert":"img文件夹存在\n"}]',
                ],
                [
                    'answer' => '[{"insert":"test文件存在\n"}]',
                    'res' => '[{"insert":"test文件不存在\n"}]',
                ]
            ], 'msg' => '']);
        } else {
            return json(['state' => 1, 'data' => [
                [
                    'answer' => '[{"insert":"img文件夹存在\n"}]',
                    'res' => '[{"insert":"img文件夹不存在\n"}]',
                ],
                [
                    'answer' => '[{"insert":"test文件存在\n"}]',
                    'res' => '[{"insert":"test文件不存在\n"}]',
                ]
            ], 'msg' => '']);
        }
    }

    private function vncRestart()
    {
        exec("vncserver -kill :2");
        var_dump(exec("vncserver :2"));
    }

    private function online()
    {
        $file = '/root/桌面/firefox-esr.desktop';
        if (file_exists($file)) {
            return json(['state' => 1, 'data' => [
                [
                    'answer' => '[{"insert":"检测到桌面存在火狐浏览器\n"}]',
                    'res' => '[{"insert":"检测到桌面存在火狐浏览器\n"}]',
                    'is_pass' => true
                ]
            ], 'msg' => '']);
        } else {
            return json(['state' => 1, 'data' => [
                [
                    'answer' => '[{"insert":"检测到桌面存在火狐浏览器\n"}]',
                    'res' => '[{"attributes":{"color":"#ff0000"},"insert":"未"},{"insert":"检测到桌面存在火狐浏览器\n"}]',
                    'is_pass' => false
                ]
            ], 'msg' => '']);
        }
    }

    private function online1()
    {
        $file = '/root/桌面/文本文档.txt';
        if (file_exists($file)) {
            $content = file_get_contents($file);
            if (trim($content) == 'kylinOS') {
                return json(['state' => 1, 'data' => [
                    [
                        'answer' => '[{"insert":"检测到文本文档\n"},{"attributes":{"color":"#a3e043"},"insert":"kylinOS"},{"insert":"\n"}]',
                        'res' => '[{"insert":"检测到文本文档\n"},{"attributes":{"color":"#a3e043"},"insert":"kylinOS"},{"insert":"\n"}]',
                        'is_pass' => true
                    ]
                ], 'msg' => '']);
            } else {
                return json(['state' => 1, 'data' => [
                    [
                        'answer' => '[{"insert":"检测到文本文档\n"},{"attributes":{"color":"#a3e043"},"insert":"kylinOS"},{"insert":"\n"}]',
                        'res' => '[{"insert":"检测到文本文档\n"},{"attributes":{"color":"#ff0000"},"insert":"' . $content . '"},{"insert":"\n"}]',
                        'is_pass' => false
                    ]
                ], 'msg' => '']);
            }
        } else {
            return json(['state' => 1, 'data' => [
                [
                    'answer' => '[{"insert":"检测到文本文档\n"},{"attributes":{"color":"#a3e043"},"insert":"kylinOS"},{"insert":"\n"}]',
                    'res' => '[{"attributes":{"color":"#ff0000"},"insert":"未"},{"insert":"检测到文本文档\n"}]',
                    'is_pass' => false
                ]
            ], 'msg' => '']);
        }
    }

    private function online2()
    {
        $dir = '/linux';
        $dirFile = '/linux/1.txt';
        $file = '/hello.txt';
        if (file_exists($dir)) {
            if (file_exists($file)) {
                if (file_exists($dirFile)) {
                    return json(['state' => 1, 'data' => [
                        [
                            'answer' => '[{"insert":"linux文件夹存在\n1.txt存在\nhello.txt不存在\n"}]',
                            'res' => '[{"insert":"linux文件夹"},{"attributes":{"color":"#a3e043"},"insert":"存在"},{"insert":"\n1.txt"},{"attributes":{"color":"#a3e043"},"insert":"存在"},{"insert":"\nhello.txt"},{"attributes":{"color":"#ff0000"},"insert":"存在"},{"insert":"\n"}]',
                            'is_pass' => false
                        ]
                    ], 'msg' => '']);
                } else {
                    return json(['state' => 1, 'data' => [
                        [
                            'answer' => '[{"insert":"linux文件夹存在\n1.txt存在\nhello.txt不存在\n"}]',
                            'res' => '[{"insert":"linux文件夹"},{"attributes":{"color":"#a3e043"},"insert":"存在"},{"insert":"\n1.txt"},{"attributes":{"color":"#ff0000"},"insert":"不存在"},{"insert":"\nhello.txt"},{"attributes":{"color":"#ff0000"},"insert":"存在"},{"insert":"\n"}]',
                            'is_pass' => false
                        ]
                    ], 'msg' => '']);
                }
            } else {
                if (file_exists($dirFile)) {
                    return json(['state' => 1, 'data' => [
                        [
                            'answer' => '[{"insert":"linux文件夹存在\n1.txt存在\nhello.txt不存在\n"}]',
                            'res' => '[{"insert":"linux文件夹"},{"attributes":{"color":"#a3e043"},"insert":"存在"},{"insert":"\n1.txt"},{"attributes":{"color":"#a3e043"},"insert":"存在"},{"insert":"\nhello.txt"},{"attributes":{"color":"#a3e043"},"insert":"不"},{"attributes":{"color":"#000000"},"insert":"存在"},{"insert":"\n"}]',
                            'is_pass' => true
                        ]
                    ], 'msg' => '']);
                } else {
                    return json(['state' => 1, 'data' => [
                        [
                            'answer' => '[{"insert":"linux文件夹存在\n1.txt存在\nhello.txt不存在\n"}]',
                            'res' => '[{"insert":"linux文件夹"},{"attributes":{"color":"#a3e043"},"insert":"存在"},{"insert":"\n1.txt"},{"attributes":{"color":"#ff0000"},"insert":"不存在"},{"insert":"\nhello.txt"},{"attributes":{"color":"#a3e043"},"insert":"不"},{"attributes":{"color":"#000000"},"insert":"存在"},{"insert":"\n"}]',
                            'is_pass' => false
                        ]
                    ], 'msg' => '']);
                }
            }
        } else {
            if (file_exists($file)) {
                return json(['state' => 1, 'data' => [
                    [
                        'answer' => '[{"insert":"linux文件夹存在\n1.txt存在\nhello.txt不存在\n"}]',
                        'res' => '[{"insert":"linux文件夹"},{"attributes":{"color":"#ff0000"},"insert":"不"},{"insert":"存在\n1.txt"},{"attributes":{"color":"#ff0000"},"insert":"不"},{"insert":"存在\nhello.txt"},{"attributes":{"color":"#ff0000"},"insert":"存在"},{"insert":"\n"}]',
                        'is_pass' => false
                    ]
                ], 'msg' => '']);
            } else {
                return json(['state' => 1, 'data' => [
                    [
                        'answer' => '[{"insert":"linux文件夹存在\n1.txt存在\nhello.txt不存在\n"}]',
                        'res' => '[{"insert":"linux文件夹"},{"attributes":{"color":"#ff0000"},"insert":"不"},{"insert":"存在\n1.txt"},{"attributes":{"color":"#ff0000"},"insert":"不"},{"insert":"存在\nhello.txt不存在\n"}]',
                        'is_pass' => false
                    ]
                ], 'msg' => '']);
            }
        }
    }

    private function online3()
    {
        $file = '/home/kylin/test.txt';
        if (file_exists($file)) {
            $content = file_get_contents($file);
            if (trim($content) == 'Hello,Linux!') {
                return json(['state' => 1, 'data' => [
                    [
                        'answer' => '[{"insert":"test.txt创建"},{"attributes":{"color":"#a3e043"},"insert":"成功！"},{"insert":"\n"},{"attributes":{"color":"#a3e043"},"insert":"Hello,Linux!"},{"insert":"\n"}]',
                        'res' => '[{"insert":"test.txt创建"},{"attributes":{"color":"#a3e043"},"insert":"成功！"},{"insert":"\n"},{"attributes":{"color":"#a3e043"},"insert":"Hello,Linux!"},{"insert":"\n"}]',
                        'is_pass' => true
                    ]
                ], 'msg' => '']);
            } else {
                return json(['state' => 1, 'data' => [
                    [
                        'answer' => '[{"insert":"test.txt创建"},{"attributes":{"color":"#a3e043"},"insert":"成功！"},{"insert":"\n"},{"attributes":{"color":"#a3e043"},"insert":"Hello,Linux!"},{"insert":"\n"}]',
                        'res' => '[{"insert":"test.txt创建"},{"attributes":{"color":"#a3e043"},"insert":"成功！"},{"insert":"\n"},{"attributes":{"color":"#ff0000"},"insert":"' . $content . '"},{"insert":"\n"}]',
                        'is_pass' => false
                    ]
                ], 'msg' => '']);
            }
        } else {
            return json(['state' => 1, 'data' => [
                [
                    'answer' => '[{"insert":"test.txt创建"},{"attributes":{"color":"#a3e043"},"insert":"成功！"},{"insert":"\n"},{"attributes":{"color":"#a3e043"},"insert":"Hello,Linux!"},{"insert":"\n"}]',
                    'res' => '[{"insert":"test.txt"},{"attributes":{"color":"#ff0000"},"insert":"未"},{"insert":"创建!\n\n"}]',
                    'is_pass' => false
                ]
            ], 'msg' => '']);
        }
    }

    private function online4()
    {
        $resFile1 = getFileperms('/root/oldFile1.txt');
        $resFile2 = getFileperms('/root/oldFile2.txt');
        $resFile3 = getFileperms('/root/oldFile3.txt');
        $resFile4 = getFileperms('/root/oldFile4.txt');
        $res = '';

        if ($resFile1) {
            $res1 = substr($resFile1, 3, 1);
            if ($res1 == 'x') {
                $res .= '[{"insert":"设置oldFile1文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},';
            } else {
                $res .= '[{"insert":"设置oldFile1文件权限"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
            }
        } else {
            $res .= '[{"insert":"设置oldFile1文件权限"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
        }

        if ($resFile2) {
            $res2 = substr($resFile2, 4, 1);
            if ($res2 == '-') {
                $res .= '{"insert":"\n设置oldFile2文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},';
            } else {
                $res .= '{"insert":"\n设置oldFile2文件权限"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
            }
        } else {
            $res .= '{"insert":"\n设置oldFile2文件权限"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
        }

        if ($resFile3) {
            $res3 = substr($resFile3, 9, 1);
            if ($res3 == 'x') {
                $res .= '{"insert":"\n设置oldFile3文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},';
            } else {
                $res .= '{"insert":"\n设置oldFile3文件权限"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
            }
        } else {
            $res .= '{"insert":"\n设置oldFile3文件权限"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
        }

        if ($resFile4) {
            $res4 = substr($resFile4, 1, 1);
            if ($res4 == 'r') {
                $res4 = substr($resFile4, 5, 1);
                if ($res4 == 'w') {
                    $res4 = substr($resFile4, 9, 1);
                    if ($res4 == 'x') {
                        $res .= '{"insert":"\n设置oldFile4文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n\n"}]';
                        return json(['state' => 1, 'data' => [
                            [
                                'answer' => '[{"insert":"设置oldFile1文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n设置oldFile2文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n设置oldFile3文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n设置oldFile4文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n"}]',
                                'res' => $res,
                                'is_pass' => true
                            ]
                        ], 'msg' => '']);
                    }
                }
            }
        }
        $res .= '{"insert":"\n设置oldFile4文件权限"},{"attributes":{"color":"#ff0000"},"insert":"失败"},{"insert":"\n\n"}]';

        return json(['state' => 1, 'data' => [
            [
                'answer' => '[{"insert":"设置oldFile1文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n设置oldFile2文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n设置oldFile3文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n设置oldFile4文件权限"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n"}]',
                'res' => $res,
                'is_pass' => true
            ]
        ], 'msg' => '']);
    }

    private function online5()
    {
        $file = '/www/admin/localhost_80/wwwroot/yk/student.txt';
        $answer = '[{"insert":"磁盘名称"},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n内存容量"},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n"}]';
        $res = '[{"insert":"磁盘名称"},{"attributes":{"color":"#ff0000"},"insert":"错误"},{"insert":"\n内存容量"},{"attributes":{"color":"#ff0000"},"insert":"错误"},{"insert":"\n"}]';
        if (file_exists($file)) {
            $content = file_get_contents($file);
            if (trim($content) == '1、磁盘名称是:/dev/vda1
2、本机内存容量是:15') {
                return json(['state' => 1, 'data' => [
                    [
                        'answer' => $answer,
                        'res' => $answer,
                        'is_pass' => true
                    ]
                ], 'msg' => '']);
            } else {
                return json(['state' => 1, 'data' => [
                    [
                        'answer' => $answer,
                        'res' => $res,
                        'is_pass' => false
                    ]
                ], 'msg' => '']);
            }
        }
        return json(['state' => 1, 'data' => [
            [
                'answer' => $answer,
                'res' => $res,
                'is_pass' => false
            ]
        ], 'msg' => '']);
    }

    private function online6()
    {
        $answer = '[{"insert":"pwd命令执行"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\ndate命令执行"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n打印当前用户命令"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n"}]';
        $res = '';
        $pass = true;
        $file = '/root/桌面/typescript';
        if (file_exists($file)) {
            $content = file_get_contents($file);
            if (strpos($content, 'pwd') !== false) {
                $res .= '[{"insert":"pwd命令执行"},{"attributes":{"color":"#a3e043"},"insert":"成功"},';
            } else {
                $res .= '[{"insert":"pwd命令执行"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
                $pass = false;
            }
            if (strpos($content, 'date +%F') !== false) {
                $res .= '{"insert":"\ndate命令执行"},{"attributes":{"color":"#a3e043"},"insert":"成功"},';
            } else {
                $res .= '{"insert":"\ndate命令执行"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
                $pass = false;
            }
            if (strpos($content, 'whoami') !== false) {
                $res .= '{"insert":"\n打印当前用户命令"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n"}]';
            } else {
                $res .= '{"insert":"\n打印当前用户命令"},{"attributes":{"color":"#ff0000"},"insert":"失败"},{"insert":"\n"}]';
                $pass = false;
            }
        } else {
            $res = '[{"insert":"pwd命令执行"},{"attributes":{"color":"#ff0000"},"insert":"失败"},{"insert":"\ndate命令执行"},{"attributes":{"color":"#ff0000"},"insert":"失败"},{"insert":"\n打印当前用户命令"},{"attributes":{"color":"#ff0000"},"insert":"失败"},{"insert":"\n"}]';
        }
        return json(['state' => 1, 'data' => [
            [
                'answer' => $answer,
                'res' => $res,
                'is_pass' => $pass
            ]
        ], 'msg' => '']);
    }

    private function online7()
    {
        $answer = '[{"insert":"kylin_user01 建立"},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":" \nkylin_user02 建立"},{"attributes":{"color":"#a3e043"},"insert":"正确 "},{"insert":"\nkylin_user03 建立"},{"attributes":{"color":"#a3e043"},"insert":"正确 "},{"insert":"\ngames 用户修改"},{"attributes":{"color":"#a3e043"},"insert":"正确 "},{"insert":"\nlp 用户删除"},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n"}]';
        $res = '';
        $pass = true;
        exec('chmod -R 777 /www/admin/localhost_80/wwwroot/yk/script/');
        exec('/www/admin/localhost_80/wwwroot/yk/script/step1.sh', $resArr);
        if ($resArr[0] == '/sbin/nologin' && $resArr[1] == true) {
            $res .= '[{"insert":"kylin_user01 建立"},{"attributes":{"color":"#a3e043"},"insert":"正确"},';
        } else {
            $res .= '[{"insert":"kylin_user01 建立"},{"attributes":{"color":"#ff0000"},"insert":"错误"},';
            $pass = false;
        }

        if ($resArr[2] == 'true') {
            $res .= '{"insert":"\nkylin_user02 建立"},{"attributes":{"color":"#a3e043"},"insert":"正确"},';
        } else {
            $res .= '{"insert":"\nkylin_user02 建立"},{"attributes":{"color":"#ff0000"},"insert":"错误"},';
            $pass = false;
        }

        if ($resArr[3] == 'true') {
            $res .= '{"insert":"\nkylin_user03 建立"},{"attributes":{"color":"#a3e043"},"insert":"正确"},';
        } else {
            $res .= '{"insert":"\nkylin_user03 建立"},{"attributes":{"color":"#ff0000"},"insert":"错误"},';
            $pass = false;
        }

        if ($resArr[4] == 'user modify test' && $resArr[5] == '/bin/bash') {
            $res .= '{"insert":"\ngames 用户修改"},{"attributes":{"color":"#a3e043"},"insert":"正确"},';
        } else {
            $res .= '{"insert":"\ngames 用户修改"},{"attributes":{"color":"#ff0000"},"insert":"错误"},';
            $pass = false;
        }

        if ($resArr[6] == 'true') {
            $res .= '{"insert":"\nlp 用户删除"},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n"}]';
        } else {
            $res .= '{"insert":"\nlp 用户删除"},{"attributes":{"color":"#ff0000"},"insert":"错误"},{"insert":"\n"}]';
            $pass = false;
        }
        return json(['state' => 1, 'data' => [
            [
                'answer' => $answer,
                'res' => $res,
                'is_pass' => $pass
            ]
        ], 'msg' => '']);
    }

    private function online8()
    {
        $answer = '[{"insert":"用户密码设置"},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\nkylin_user02用户密码属性设置"},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\ngames用户锁定"},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n"}]';
        $res = '';
        $pass = true;
        exec('chmod -R 777 /www/admin/localhost_80/wwwroot/yk/script/');
        exec('/www/admin/localhost_80/wwwroot/yk/script/step2.sh', $resArr);
        if ($resArr[0] == 'true') {
            $res .= '[{"insert":"用户密码设置"},{"attributes":{"color":"#a3e043"},"insert":"正确"},';
        } else {
            $res .= '[{"insert":"用户密码设置"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
            $pass = false;
        }
        if ($resArr[1] == 'true') {
            $res .= '{"insert":"\nkylin_user02用户密码属性设置"},{"attributes":{"color":"#a3e043"},"insert":"正确"},';
        } else {
            $res .= '{"insert":"\nkylin_user02用户密码属性设置"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
            $pass = false;
        }
        if ($resArr[2] == 'L') {
            $res .= '{"insert":"\ngames用户锁定"},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n"}]';
        } else {
            $res .= '{"insert":"\ngames用户锁定"},{"attributes":{"color":"#ff0000"},"insert":"失败"},{"insert":"\n"}]';
            $pass = false;
        }
        return json(['state' => 1, 'data' => [
            [
                'answer' => $answer,
                'res' => $res,
                'is_pass' => $pass
            ]
        ], 'msg' => '']);
    }

    private function online9()
    {
        $answer = '[{"insert":"kyadmin 组账号创建"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n修改ssh组账号"},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\nstaff组账号删除"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n"}]';
        $res = '';
        $pass = true;
        exec('chmod -R 777 /www/admin/localhost_80/wwwroot/yk/script/');
        exec('/www/admin/localhost_80/wwwroot/yk/script/step3.sh', $resArr);
        if ($resArr[0] == 'kylin_user03' && $resArr[1] == 'true') {
            $res .= '[{"insert":"kyadmin 组账号创建"},{"attributes":{"color":"#a3e043"},"insert":"成功"},';
        } else {
            $res .= '[{"insert":"kyadmin 组账号创建"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
            $pass = false;
        }
        if ($resArr[2] == 'true') {
            $res .= '{"insert":"\n修改ssh组账号"},{"attributes":{"color":"#a3e043"},"insert":"正确"},';
        } else {
            $res .= '{"insert":"\n修改ssh组账号"},{"attributes":{"color":"#ff0000"},"insert":"错误"},';
            $pass = false;
        }
        if ($resArr[3] == 'true') {
            $res .= '{"insert":"\nstaff组账号删除"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n"}]';
        } else {
            $res .= '{"insert":"\nstaff组账号删除"},{"attributes":{"color":"#ff0000"},"insert":"失败"},{"insert":"\n"}]';
            $pass = false;
        }
        return json(['state' => 1, 'data' => [
            [
                'answer' => $answer,
                'res' => $res,
                'is_pass' => $pass
            ]
        ], 'msg' => '']);
    }

    private function online10()
    {
        $answer = '[{"insert":"删除vino软件包"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\ndocker升级"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n"}]';
        $res = '';
        $pass = true;
        exec('chmod -R 777 /www/admin/localhost_80/wwwroot/yk/script/');
        exec('/www/admin/localhost_80/wwwroot/yk/script/step4.sh', $resArr);
        if ($resArr[0] == 'true') {
            $res .= '[{"insert":"删除vino软件包"},{"attributes":{"color":"#a3e043"},"insert":"成功"},';
        } else {
            $res .= '[{"insert":"删除vino软件包"},{"attributes":{"color":"#ff0000"},"insert":"失败"},';
            $pass = false;
        }
        if ($resArr[1] == 'true') {
            $res .= '{"insert":"\ndocker升级"},{"attributes":{"color":"#a3e043"},"insert":"成功"},{"insert":"\n"}]';
        } else {
            $res .= '{"insert":"\ndocker升级"},{"attributes":{"color":"#ff0000"},"insert":"失败"},{"insert":"\n"}]';
            $pass = false;
        }
        return json(['state' => 1, 'data' => [
            [
                'answer' => $answer,
                'res' => $res,
                'is_pass' => $pass
            ]
        ], 'msg' => '']);
    }

    private function online11()
    {
        $answer = '[{"insert":"复制86-88行，粘贴到末尾: "},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n删除136-139行: "},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n将文中所有john替换为jhon: "},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n在88行尾添加内容 I love china: "},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n在90行末尾新添加一行内容 Love me, love my dog: "},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n"}]';
        $res = '';
        $pass = true;
        exec('chmod -R 777 /www/admin/localhost_80/wwwroot/yk/script/');
        exec('/www/admin/localhost_80/wwwroot/yk/script/step5.sh', $resArr);
        if ($resArr[0] == 'not found') {
            return json(['state' => 1, 'data' => [
                [
                    'answer' => $answer,
                    'res' => '[{"attributes":{"color":"#ff0000"},"insert":"未发现vim_text.txt文件"},{"insert":"\n"}]',
                    'is_pass' => false
                ]
            ], 'msg' => '']);
        }
        if ($resArr[0] == 'true') {
            $res .= '[{"insert":"复制86-88行，粘贴到末尾: "},{"attributes":{"color":"#a3e043"},"insert":"正确"},';
        } else {
            $res .= '[{"insert":"复制86-88行，粘贴到末尾: "},{"attributes":{"color":"#ff0000"},"insert":"错误"},';
            $pass = false;
        }
        if ($resArr[1] == 'true') {
            $res .= '{"insert":"\n删除136-139行: "},{"attributes":{"color":"#a3e043"},"insert":"正确"},';
        } else {
            $res .= '{"insert":"\n删除136-139行: "},{"attributes":{"color":"#ff0000"},"insert":"错误"},';
            $pass = false;
        }
        if ($resArr[2] == 'true') {
            $res .= '{"insert":"\n将文中所有john替换为jhon: "},{"attributes":{"color":"#a3e043"},"insert":"正确"},';
        } else {
            $res .= '{"insert":"\n将文中所有john替换为jhon: "},{"attributes":{"color":"#ff0000"},"insert":"错误"},';
            $pass = false;
        }
        if ($resArr[3] == 'true') {
            $res .= '{"insert":"\n在88行尾添加内容 I love china: "},{"attributes":{"color":"#a3e043"},"insert":"正确"},';
        } else {
            $res .= '{"insert":"\n在88行尾添加内容 I love china: "},{"attributes":{"color":"#ff0000"},"insert":"错误"},';
            $pass = false;
        }
        if ($resArr[4] == 'true') {
            $res .= '{"insert":"\n在90行末尾新添加一行内容 Love me, love my dog: "},{"attributes":{"color":"#a3e043"},"insert":"正确"},{"insert":"\n"}]';
        } else {
            $res .= '{"insert":"\n在90行末尾新添加一行内容 Love me, love my dog: "},{"attributes":{"color":"#ff0000"},"insert":"错误"},{"insert":"\n"}]';
            $pass = false;
        }
        return json(['state' => 1, 'data' => [
            [
                'answer' => $answer,
                'res' => $res,
                'is_pass' => $pass
            ]
        ], 'msg' => '']);
    }
}
